package com.baomidou.mybatisplus.generator;

import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.DbType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

public class Start {

	public static void main(String[] args) {

		AutoGenerator ag = new AutoGenerator();
		// 设置名称
		GlobalConfig gc = new GlobalConfig();
		setDefaultProperties(ag, gc);
		// 设置数据源
		StrategyConfig strategy = getStrategyConfig();
		DataSourceConfig dsc = new DataSourceConfig();

		gc.setAuthor("代码生成器");
		gc.setProjectName("sop服务");
		// 用于打印日志

		dsc.setDbType(DbType.MYSQL);
		dsc.setDriverName("com.mysql.jdbc.Driver");
		dsc.setUsername("dev_jibiandang");
		dsc.setPassword("dev_jibiandang@123456");
		dsc.setUrl("jdbc:mysql://172.18.13.173:3306/dev_jbd_supplychain");
		ag.setDataSource(dsc);
		// 设置超类
		// 指定生成的那些表
		strategy.setTablePrefix("jbd_sop_");
		strategy.setInclude("jbd_sop_product_count","jbd_sop_material_supplier_ref","jbd_sop_material_spec","jbd_sop_material_ref","jbd_sop_material_acceptance",
				"jbd_sop_material",
				"jbd_sop_count_process","jbd_sop_count_dishes","jbd_sop_count_material");
		ag.setStrategy(strategy);
		// 设置包信息
		ag.execute();

	}

	private static StrategyConfig getStrategyConfig() {
		StrategyConfig strategy = new StrategyConfig();

		strategy.setNaming(NamingStrategy.underline_to_camel);
		strategy.setEntityBooleanColumnRemoveIsPrefix(false);
		return strategy;
	}

	private static void setDefaultProperties(AutoGenerator ag, GlobalConfig gc) {
		gc.setOutputDir("D:\\gen\\code");
		gc.setFileOverride(true);
		gc.setActiveRecord(false);
		gc.setEnableCache(false);
		gc.setBaseResultMap(true);
		gc.setBaseColumnList(true);
		gc.setControllerName("%sDaoImpl");
		gc.setMapperName("%sDao");
		gc.setServiceName("%sRpc");
		gc.setServiceImplName("%sRpcImpl");
		gc.setXmlName("%sMapper");
		gc.setKotlin(false);
		gc.setOpen(true);
		ag.setGlobalConfig(gc);
	}

}
